
require 'yaml'
require 'thefox-ext'

module TheFox
	module PSort

		class Config
			
			def initialize(file_path)
				@file_path = file_path
				@data = {
					'title' => nil,
					'types' => {
						'jpg' => {
							'move_to_subdir' => false,
							'subdir_name' => nil,
						},
						'png' => {
							'move_to_subdir' => false,
							'subdir_name' => nil,
						},
						'mov' => {
							'move_to_subdir' => false,
							'subdir_name' => nil,
						},
					},
				}
				
				load_from_file(@file_path)
			end
			
			def load_from_file(file_path)
				if File.exist?(file_path)
					puts "load '#{file_path}'"
					config = YAML.load_file(file_path)
					if !config.nil?
						@data.merge_recursive!(config)
					end
				end
			end
			
			def [](key)
				@data[key]
			end
			
		end
		
	end
end
